package com.application.fabric.水印.添加和提取水印;

import java.awt.image.BufferedImage;

public class WatermarkExtractor {
    private static final int WATERMARK_WIDTH = 100;
    private static final int WATERMARK_HEIGHT = 100;

    public BufferedImage extract(int[] pixels, int width, int height) {
        // 创建水印像素数组
        int[] watermarkPixels = new int[WATERMARK_WIDTH * WATERMARK_HEIGHT];

        // 将像素数组中的水印部分提取出来
        for (int y = 0; y < WATERMARK_HEIGHT; y++) {
            for (int x = 0; x < WATERMARK_WIDTH; x++) {
                int pixelIndex = y * WATERMARK_WIDTH + x;
                int imageX = width - WATERMARK_WIDTH + x;
                int imageY = height - WATERMARK_HEIGHT + y;
                int imageIndex = imageY * width + imageX;
                watermarkPixels[pixelIndex] = pixels[imageIndex];
            }
        }

        // 创建水印图像对象
        BufferedImage watermarkImage = new BufferedImage(WATERMARK_WIDTH, WATERMARK_HEIGHT, BufferedImage.TYPE_INT_RGB);
        watermarkImage.setRGB(0, 0, WATERMARK_WIDTH, WATERMARK_HEIGHT, watermarkPixels, 0, WATERMARK_WIDTH);

        return watermarkImage;
    }
}
